1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gdk.DrawContext;
26 
27 private import cairo.Region;
28 private import gdk.Display;
29 private import gdk.Surface;
30 private import gdk.c.functions;
31 public  import gdk.c.types;
32 private import gobject.ObjectG;
33 
34 
35 /**
36  * Base class for objects implementing different rendering methods.
37  * 
38  * `GdkDrawContext` is the base object used by contexts implementing different
39  * rendering methods, such as [class@Gdk.CairoContext] or [class@Gdk.GLContext].
40  * It provides shared functionality between those contexts.
41  * 
42  * You will always interact with one of those subclasses.
43  * 
44  * A `GdkDrawContext` is always associated with a single toplevel surface.
45  */
46 public class DrawContext : ObjectG
47 {
48 	/** the main Gtk struct */
49 	protected GdkDrawContext* gdkDrawContext;
50 
51 	/** Get the main Gtk struct */
52 	public GdkDrawContext* getDrawContextStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return gdkDrawContext;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gdkDrawContext;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GdkDrawContext* gdkDrawContext, bool ownedRef = false)
69 	{
70 		this.gdkDrawContext = gdkDrawContext;
71 		super(cast(GObject*)gdkDrawContext, ownedRef);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return gdk_draw_context_get_type();
79 	}
80 
81 	/**
82 	 * Indicates that you are beginning the process of redrawing @region
83 	 * on the @context's surface.
84 	 *
85 	 * Calling this function begins a drawing operation using @context on the
86 	 * surface that @context was created from. The actual requirements and
87 	 * guarantees for the drawing operation vary for different implementations
88 	 * of drawing, so a [class@Gdk.CairoContext] and a [class@Gdk.GLContext]
89 	 * need to be treated differently.
90 	 *
91 	 * A call to this function is a requirement for drawing and must be
92 	 * followed by a call to [method@Gdk.DrawContext.end_frame], which will
93 	 * complete the drawing operation and ensure the contents become visible
94 	 * on screen.
95 	 *
96 	 * Note that the @region passed to this function is the minimum region that
97 	 * needs to be drawn and depending on implementation, windowing system and
98 	 * hardware in use, it might be necessary to draw a larger region. Drawing
99 	 * implementation must use [method@Gdk.DrawContext.get_frame_region] to
100 	 * query the region that must be drawn.
101 	 *
102 	 * When using GTK, the widget system automatically places calls to
103 	 * gdk_draw_context_begin_frame() and gdk_draw_context_end_frame() via the
104 	 * use of [class@Gsk.Renderer]s, so application code does not need to call
105 	 * these functions explicitly.
106 	 *
107 	 * Params:
108 	 *     region = minimum region that should be drawn
109 	 */
110 	public void beginFrame(Region region)
111 	{
112 		gdk_draw_context_begin_frame(gdkDrawContext, (region is null) ? null : region.getRegionStruct());
113 	}
114 
115 	/**
116 	 * Ends a drawing operation started with gdk_draw_context_begin_frame().
117 	 *
118 	 * This makes the drawing available on screen.
119 	 * See [method@Gdk.DrawContext.begin_frame] for more details about drawing.
120 	 *
121 	 * When using a [class@Gdk.GLContext], this function may call `glFlush()`
122 	 * implicitly before returning; it is not recommended to call `glFlush()`
123 	 * explicitly before calling this function.
124 	 */
125 	public void endFrame()
126 	{
127 		gdk_draw_context_end_frame(gdkDrawContext);
128 	}
129 
130 	/**
131 	 * Retrieves the `GdkDisplay` the @context is created for
132 	 *
133 	 * Returns: the `GdkDisplay`
134 	 */
135 	public Display getDisplay()
136 	{
137 		auto __p = gdk_draw_context_get_display(gdkDrawContext);
138 
139 		if(__p is null)
140 		{
141 			return null;
142 		}
143 
144 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
145 	}
146 
147 	/**
148 	 * Retrieves the region that is currently being repainted.
149 	 *
150 	 * After a call to [method@Gdk.DrawContext.begin_frame] this function will
151 	 * return a union of the region passed to that function and the area of the
152 	 * surface that the @context determined needs to be repainted.
153 	 *
154 	 * If @context is not in between calls to [method@Gdk.DrawContext.begin_frame]
155 	 * and [method@Gdk.DrawContext.end_frame], %NULL will be returned.
156 	 *
157 	 * Returns: a Cairo region
158 	 */
159 	public Region getFrameRegion()
160 	{
161 		auto __p = gdk_draw_context_get_frame_region(gdkDrawContext);
162 
163 		if(__p is null)
164 		{
165 			return null;
166 		}
167 
168 		return new Region(cast(cairo_region_t*) __p);
169 	}
170 
171 	/**
172 	 * Retrieves the surface that @context is bound to.
173 	 *
174 	 * Returns: a `GdkSurface`
175 	 */
176 	public Surface getSurface()
177 	{
178 		auto __p = gdk_draw_context_get_surface(gdkDrawContext);
179 
180 		if(__p is null)
181 		{
182 			return null;
183 		}
184 
185 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
186 	}
187 
188 	/**
189 	 * Returns %TRUE if @context is in the process of drawing to its surface.
190 	 *
191 	 * This is the case between calls to [method@Gdk.DrawContext.begin_frame]
192 	 * and [method@Gdk.DrawContext.end_frame]. In this situation, drawing commands
193 	 * may be effecting the contents of the @context's surface.
194 	 *
195 	 * Returns: %TRUE if the context is between [method@Gdk.DrawContext.begin_frame]
196 	 *     and [method@Gdk.DrawContext.end_frame] calls.
197 	 */
198 	public bool isInFrame()
199 	{
200 		return gdk_draw_context_is_in_frame(gdkDrawContext) != 0;
201 	}
202 }